package org.example.backend.util;

public class BCryptExample {
    public static void main(String[] args) {
        String password = "667985";
        // 1. 基本哈希和验证
        String hashed = BCryptUtils.hash(password);
        System.out.println("Hashed password: " + hashed);
        System.out.println("Is valid: " + BCryptUtils.verify(password, hashed));

        // 2. 使用更高工作因子
        String strongHash = BCryptUtils.hash(password, 12);
        System.out.println("Strong hashed password: " + strongHash);

        // 3. 检查哈希有效性
        String invalidHash = "invalid_hash";
        System.out.println("Is valid BCrypt hash: " + BCryptUtils.isValidBCryptHash(invalidHash));

        // 4. 提取工作因子
        int cost = BCryptUtils.extractCostFactor(hashed);
        System.out.println("Cost factor: " + cost);

        // 5. 升级哈希
        String upgradedHash = BCryptUtils.upgradeHash(password, hashed, 12);
        if (upgradedHash != null) {
            System.out.println("Upgraded hash: " + upgradedHash);
            System.out.println("New cost factor: " +
                    BCryptUtils.extractCostFactor(upgradedHash));
        }
    }
}